package expressions.slogo;

import java.util.List;
import parsing.Token;
import model.Turtle;
import model.Angle;

/**
 * Turns the turtle to face a new absolute angle.
 */
@Token(regex = "setheading|seth")
public class SetHeading extends TurtleCommand
{

    public SetHeading()
    {
        super(1);
    }

    @Override
    protected Double combineResults(List<Double> results, ITurtleContext context)
    {
        Turtle t = context.getTurtle();
        double oldradians = t.getAngle().getRadians();
        double newradians = Angle.degreesToRadians(results.get(0));

        /*
         * Turn the turtle to the new angle.
         */
        t.turn(newradians);

        /*
         * Return how many degrees was turned.
         */
        return Angle.radiansToDegrees(newradians - oldradians);
    }

}
